package com.bawei.mall.pay;

import com.alibaba.fastjson.JSONObject;
import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.request.AlipayTradeWapPayRequest;
import com.alipay.api.response.AlipayTradeWapPayResponse;

public class TestMain {
    public static void main(String[] args) {
        AlipayClient alipayClient = new DefaultAlipayClient(
                "https://openapi.alipay.com/gateway.do",
                "9021000139610858",
                "MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCnwCRULnfNnftes23ng9k4hgfLhMoWyA6u71PrataFNStNYas9gx/wdBxOun0GMC84YPn6mkPrfAGR5aFqh1dRw97SNZK3ajjxnx2v6o47dhcndUCnq2TK/sEEFqNReTlu1ad5chF+zsQ8l+kMbOXDUyahHWScylqG8aJatgOnNBJj2DawhQ4GmxNe0aeiXHmyPk+EG9Thz9qAXOvApjNzqPahx1XnKaVGV7I3bmncxxPem9T9nbi1znWylSJqFnTgrPy+jMtZv2aTvZbFPwPrOJt8gXe51MfYtUScso5nNZzFABF/brAsn/0q/o0j7lJBnfe0kJZ5wVO4ncU8+/wNAgMBAAECggEAM7G+gEKhoLeikxhwMfwroIONO2Z8cHDONZKDJfUSjpJH+dyzTI1v9kWRw6Esjg+jPZiE8HlBnPvl7/P3vkBe5E+cBuODhwow6iTCnUeG9UP69qnndsQWl4fSK1Rel+jnjgRBS+efBJjrWFDn/HBCjeK98MCCFN827obgJVwZ3Bhpx+j1aNVGua4v9Ipc0iF2DCd3PPon18oiRzvvszRPHBNWEDjMf0ABQSi0Ju8HOTT6PrTaW4Z+3XvugR7cRIjT4HQ7B4QzWmIXZL0M8qas6jTO9hmmwokRCcy6Kh4gUGwlOh9z3Hd06XgNsLinVib8ftRxZ9gBMtmp64NQLlnncQKBgQD7StPr4qGhUsTb/Scw/QzGt9BT5yjWEgeU7OowexwKFJdHS1Y9nJO9qckED01zqYT/rzWs6R/8riNWMqMjwg4h13YIBoWFYMPkmRhLZoNHlAMypdMxmFvknNrJLM6XjdaYace5/MSXUiwEIJCnDslRj7sEw3oqlL0wFRUiRXbdiwKBgQCq5KgL6OEME1mRPljdaimebEokuknj3ReYj0Mvfnqq9rDqkILh798QG8wdqFENN2nJTPhr6n+HjXBBwwIZyks/S9ZShdeTdwMXNpI1a1z6IvZr5QWf33V+9RmooNC3ihDP2ZBJXYH5M+6Ia1gLhEGdzQAzoqHKhWeO6WMRyGPvxwKBgQCqNQbR0VG1GYDpmNDA58WNm9dp3TrVtKSaBNajO9/EHCpTSf4CAVo4rxXOwCav3vSM0rpCgiz+U1zv96B0ie5UkcIKsZAixWYqImBIQglNpD1+Qr+H6jDj6jJu7QCJurLNzWhQ25q0/B2ANiaEYQmPSxFbqqPGz7RNKxqDehWG/QKBgAi67arOFtEbG/RDjx6gkce6GH+P1L6DSPVOPExs1a9uMtOI1mbcbjTQdrj9JEbckdbqy7YXoLQ4EYgKgkz2/KkbIrPMiprJ9ap16zo3ZeSRbK1OYd8s9z+pHcpzjLYTo5A6uRhGYqFseb8WXMUZ2JBLLLt2j3VdI1E1sw3xgsl5AoGBAJi15Uk0sBjReRlkSry15cpdbyfcFuDhBS+cc1CyWOLvj9RqMnisKgIsQ1K8fNCC3/S55ct1BVfNohYbjrfRAkKMYbNjidkBrxdGNURsTCEDK9EecGDIvaF1m9nC5aQmwJfBapJlohsUOvSj8wWjroD36+MkfkbI9yht8vMFwIVI",
                "json",
                "GBK",
                "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAoBai8Zb+A4SUKYxADoW36lYJ+7U9S0lz44oKJS55zets7WZ1eHvYdNuX8ramdj4R9lwbuVTixM7OyEkEwepqdhmMRAf7nW6waQ++sFL+vybM30csDaaVnbP0vzOf8+Iq3oqBMijBDWd2HIfq6nZLowZ7dwBi6zoalw58kYtk8oF650OTd6psuVC3ua4FmJy5CmyrcqPEymZzsylVoh/btomR5b9V9hFf4Oib+6q34K+1xDysGhdL9nIPfwKFthBUmByBxQIEKzI1cbee/kWCNXvG0MXUFBYA1BAJg84gROebe1nBQECuL7atbD8iTPlqYOgAVmHZ+QwPImfU4Z+2twIDAQAB",
                "RSA2");
        AlipayTradeWapPayRequest request = new AlipayTradeWapPayRequest();
//异步接收地址，仅支持http/https，公网可访问
        request.setNotifyUrl("");
//同步跳转地址，仅支持http/https
        request.setReturnUrl("");
/******必传参数******/
        JSONObject bizContent = new JSONObject();
//商户订单号，商家自定义，保持唯一性
        bizContent.put("out_trade_no", "20210817010101004");
//支付金额，最小值0.01元
        bizContent.put("total_amount", 0.01);
//订单标题，不可使用特殊符号
        bizContent.put("subject", "测试商品");

/******可选参数******/
        bizContent.put("product_code", "QUICK_WAP_WAY");

        request.setBizContent(bizContent.toString());
        AlipayTradeWapPayResponse response = null;
        try {
            response = alipayClient.pageExecute(request,"POST");
        } catch (AlipayApiException e) {
            throw new RuntimeException(e);
        }
// 如果需要返回GET请求，请使用
// AlipayTradeWapPayResponse response = alipayClient.pageExecute(request,"GET");
        String pageRedirectionData = response.getBody();
        System.out.println(pageRedirectionData);

        if(response.isSuccess()){
            System.out.println("调用成功");
        } else {
            System.out.println("调用失败");
        }
    }
}
